"""
@Project:project2
@File:serializers.py
@Author:田诚
@Date:19:08
"""


from myapp.models import Press,Author,Book
from rest_framework import serializers

class PressSet(serializers.ModelSerializer):
    class Meta:
        model = Press
        fields = '__all__'

class AuthorSet(serializers.ModelSerializer):
    class Meta:
        model = Author
        fields = '__all__'

class BookSet(serializers.ModelSerializer):
    author_name = serializers.SerializerMethodField(read_only=True)
    press_name = serializers.SerializerMethodField(read_only=True)
    def get_author_name(self,obj):
        return obj.author.name
    def get_press_name(self,obj):
        return obj.press.press_name

    class Meta:
        model = Book
        fields = '__all__'



